﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ResizeImage.ascx.cs" Inherits="admin_webparts_Plug_ins_Files_ResizeImage" %>
<%@ Import Namespace="NTTHAO.CommonWeb" %>

<div class="tip">
    <h1>Resize image</h1>
    <table cellspacing="0" cellpadding="0" border="0" width="100%" style="margin-top: 20px;">
        <tr>
            <td align="left">
                <a class="path" href="?type=page&name=files&file=%2f"><%=WebGlobal.GetSite(System.Web.HttpContext.Current.Session).SiteID%></a> 
                <%
                    string[] parents = this._CurrentPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                    string path = "/";
                    for(int i = 0; i < parents.Length; i++)
                    {
                        string dir = parents[i];
                        path += dir + "/";
                        if (i < parents.Length - 1) {    
                %>
                /&nbsp;<a class="path" href="?type=page&name=files&file=<%=Server.UrlEncode(path) %>"><%=dir%></a>
                    <%} else {%>
                /&nbsp;<span class="path"><%=dir%></span>
                    <%} %>
                <%} %>
            </td>
        </tr>
    </table>
</div>
<%if(this._Message != string.Empty) { %>
<div class="tip tip_highlight">
    <span class="b">Message:&nbsp;</span><span class="red"><%=this._Message %></span>
</div>
<%} %>
<form id="frm" runat="server">
<% string imagePath = ROOT_PATH.TrimEnd('/') + this._CurrentPath; %>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function() {
    var preloadImage = new Image();
	preloadImage.onload = function(){
	    var txtWidth = document.getElementById("<%=txtWidth.ClientID %>");
	    var txtHeight = document.getElementById("<%=txtHeight.ClientID %>");
        txtWidth.value = document.getElementById("txtOriginalWidth").value = this.width;
        txtHeight.value = document.getElementById("txtOriginalHeight").value = this.height;
        txtWidth.focus();
        txtWidth.select();
	};
	preloadImage.src = '<%=imagePath %>';
});
function blurItem(item, type) {
    var txtWidth = document.getElementById("<%=txtWidth.ClientID %>");
    var txtHeight = document.getElementById("<%=txtHeight.ClientID %>");
    var txtOriginalWidth = document.getElementById("txtOriginalWidth");
    var txtOriginalHeight = document.getElementById("txtOriginalHeight");
    
    var originalValue = ('width' === type) ? txtOriginalWidth.value : txtOriginalHeight.value;
    var inputValue = 0;
    
    try {
        item.value = item.value.trim();
        if (isNaN(parseInt(item.value, 10)) || parseInt(item.value, 10) < 1) {
            txtWidth.value = txtOriginalWidth.value;
            txtHeight.value = txtOriginalHeight.value;
            return;
        } else {
            inputValue = parseInt(item.value.trim(), 10);
            item.value = '' + inputValue;
        }
    } catch (e) { }
    
    var originalWidth = parseInt(txtOriginalWidth.value, 10);
    var originalHeight = parseInt(txtOriginalHeight.value, 10);
    var ratio = originalWidth * 1.0 / originalHeight;
    
    if('width' === type) {
        txtHeight.value = Math.round(inputValue / ratio);
    } else if('height' === type) {
        txtWidth.value = Math.round(inputValue * ratio);
    }
}
</script>
<table cellspacing="0" cellpadding="0" border="1" class="grid" style="margin: 10px auto;">
    <tr class="odd">
        <td align="right"><%=LanguageUtility.GetLanguageText("IMAGE_TO_RESIZE", Session)%>:</td>
        <td>
            <a href="<%=imagePath %>" target="_blank"><img alt="" src="<%=imagePath %>" style="max-width: 200px; max-height: 150px;padding: 5px 0px;" /></a>
        </td>
    </tr>
    <tr class="even">
        <td align="right" width="140px" style="white-space: nowrap;"><%=LanguageUtility.GetLanguageText("ORIGINAL_SIZE")%>:</td>
        <td><input type="text" id="txtOriginalWidth" value="0" style="width: 50px;" disabled="disabled" /> x <input type="text" id="txtOriginalHeight" value="0" style="width: 50px;" disabled="disabled" /><b> pixels</b>
        </td>
    </tr>
    <tr class="odd">
        <td align="right" style="white-space: nowrap;">
            <%=LanguageUtility.GetLanguageText("RESIZE_SIZE")%>:
        </td>
        <td>
            <asp:TextBox ID="txtWidth" runat="server" Text="1024" Width="50px" onblur="blurItem(this, 'width');"></asp:TextBox> x <asp:TextBox ID="txtHeight" runat="server" Text="1024" Width="50px" onblur="blurItem(this, 'height');"></asp:TextBox><b> pixels</b>
        </td>
    </tr>
    <tr class="even" style="<%=Constant.ADD_LAYER_MASK ? "" : "display: none;"%>">
        <td align="right">Đính kèm logo:</td>
        <td><asp:CheckBox ID="chkLayerMask" Text="Đính kèm logo (đối với file ảnh *.jpg)" runat="server" /></td>
    </tr>
</table>
<p>
    <span id="spSave1" class="yui-button yui-link-button yuibtn yuibtn-icon btnsave"><span class="first-child"><asp:Button ID="btnSave1" runat="server" OnClick="btnSave_Click" Text="Save" /></span></span>
    <span id="spCancel1" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><a href="?type=page&name=files&file=<%=Server.UrlEncode(this.ParentPath) %>" tabindex="0"><%=LanguageUtility.GetLanguageText("CANCEL", Session)%></a></span></span>
</p>
</form>
<style type="text/css">
    #spCancel1, #spSave1, #spCancel2, #spSave2 {font-size:1.1em; font-weight: bold; }
    #spCancel1 button, #spSave1 button, #spCancel2 button, #spSave2 button { font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: bold; }
</style>
<script type="text/javascript"> 
YAHOO.util.Event.onContentReady("spCancel1", function () {
    var spCancel1 = new YAHOO.widget.Button("spCancel1");
});
YAHOO.util.Event.onContentReady("spSave1", function () {
    var spSave = new YAHOO.widget.Button("spSave1");
});
</script>